#pragma once

#include "IDatabase.h"
#include "IResultSet.h"

#include <vector>

LIBDBC_BEGIN_NAMESPACE

class SqlResult;

class Database : public IDatabase
{
public:
	Database();
	~Database();

	bool hasResultSet(IResultSet* prs);
	bool freeResultSet(IResultSet* prs);

	bool removeFromResultSetWithoutDeletion(IResultSet* prs);
	const char* getLastError() { return _szLastError; }

protected:

	virtual bool _connect(const char* host, const char* database, const char* user, const char* pwd, int port = 0);
	virtual bool _connect(const char* host, const char* user, const char* pwd, int port = 0);
	virtual bool _close();
	virtual IResultSet* _execQuery(const char* query);

	int _execInsert(const char* query);
	int _execUpdate(const char* query);
	int _execDelete(const char* query);
	int _execDML(const char* query);

	virtual void _use(const char* database);
	virtual void _beginTransaction();
	virtual bool _commit();
	virtual bool _rollback();

	virtual int _execNonQuery(const char* query);
	IResultSet* _createResultSet(SqlResult* pResult);
	void _setLastError(const char* err);

protected:
	char* _szLastError;
	std::vector<IResultSet*> _results;
};


LIBDBC_END_NAMESPACE